<script setup lang="ts">
import { createTextVNode, defineComponent } from 'vue';

import {
  NDialogProvider,
  NLoadingBarProvider,
  NMessageProvider,
  NModalProvider,
  NNotificationProvider,
  useDialog,
  useLoadingBar,
  useMessage,
  useModal,
  useNotification,
} from 'naive-ui';

defineOptions({
  name: 'WProvider',
});

const ContextHolder = defineComponent({
  name: 'ContextHolder',
  setup() {
    function register() {
      window.loadingBar = useLoadingBar();
      window.dialog = useDialog();
      window.message = useMessage();
      window.notification = useNotification();
      window.modal = useModal();
    }
    register();
    return () => createTextVNode();
  },
});
</script>

<template>
  <NLoadingBarProvider>
    <NDialogProvider>
      <NModalProvider>
        <NNotificationProvider>
          <NMessageProvider>
            <ContextHolder />
            <slot></slot>
          </NMessageProvider>
        </NNotificationProvider>
      </NModalProvider>
    </NDialogProvider>
  </NLoadingBarProvider>
</template>

<style scoped></style>
